package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-05-13
 * Time: 13:35
 */
public class BorrowBook implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("*************Borrow Book*************");
        System.out.println("请输入您所要借阅图书的书名:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currentNum = bookList.getBookNumber();
        for (int i = 0; i < currentNum; i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())) {
                if(book.getBorrowed() == true) {
                    System.out.println("很抱歉！！！该书籍已被其他人借阅！！！");
                    return;
                }else {
                    book.setBorrowed(true);
                    System.out.println("借阅成功！");
                    return;
                }
            }
        }
        System.out.println("没有查找到该书籍！！！");
    }
}
